// 审核
import store from '../index'
import { StandingBookModel, ApprovalFlowModel } from '@/models'
const standingBookModel = new StandingBookModel()
const approvalFlow = new ApprovalFlowModel()

const getDefaultState = () => {
    return {
        info: {}
    }
}

const state = getDefaultState()

const getters = {}

const mutations = {
    setInfo(state, info) {
        state.info = info
    }
}

const actions = {
    // 巡查计划详情
    async getPlanDetail({ commit }, { id, number }) {
        const res = await store.dispatch('inspection-plan/detail', {
            id,
            edit: false,
            number
        })
        commit('setInfo', res)
        console.log('res :>> ', res)
    },
    // 获取路产赔付详情
    async getPayoutDetail({ commit }, number) {
        try {
            store.commit('openLoading')
            const res = await standingBookModel.detail({ number }, 'filter')
            commit('setInfo', res)
        } finally {
            store.commit('closeLoading')
        }
    },
    // 批复
    async approve({ commit }, data = {}) {
        try {
            store.commit('openBtnLoading')
            const res = await approvalFlow.approve(data)
        } finally {
            store.commit('closeBtnLoading')
        }
    },
    // 审核
    async audit({ commit }, data = {}) {
        try {
            store.commit('openBtnLoading')
            const res = await approvalFlow.audit(data)
            return res
        } finally {
            store.commit('closeBtnLoading')
        }
    }
}

export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}
